## This code creates Table 4.

data <- colonial_towns_shp[colonial_towns_shp$year == 1924,]

covariates <- c("railway","post","telegraph","bazaar","f_revenue","hospital","school") # List of covariates for balance check

balance_check <- matrix(nrow = 7,ncol=8) # Create empty data frame for balance check

# Loop regressions with headman status as DV and covariate as IV

for(i in 1:length(covariates)){
  balance_check[1,i+1] <- covariates[i]
  model <- conleyreg(paste0(covariates[i],"~replaced+log(houses)+altitude+slope_idx+as.factor(soil_quality)+log(yangon_dist)+log(river_dist)+as.factor(district)+longitude_2+latitude_2"),data=data@data,dist_cutoff=100,lat="latitude",lon="longitude",gof=TRUE)
  coef <- round(model$coefficients[2],digits=4)
  se <- round(model$coefficients[2,2],digits=4)
  balance_check[2,i+1] <- coef
  balance_check[3,i+1] <- paste0("(",se,")")
  balance_check[4,i+1] <- paste0("[",round(coef-1.96*se,digits=4),",")
  balance_check[5,i+1] <- paste0(round(coef+1.96*se,digits=4),"]")
  balance_check[6,i+1] <- nobs(model)
  balance_check[7,i+1] <- round(model$adj.r.squared,digits=4)
}

# Produce table

xtable(balance_check)
